package net.lab1024.sa.admin.module.business.erp.service;

import java.util.List;
import net.lab1024.sa.admin.module.business.erp.dao.AccountaDao;
import net.lab1024.sa.admin.module.business.erp.domain.entity.AccountaEntity;
import net.lab1024.sa.admin.module.business.erp.domain.form.add.AccountaAddForm;
import net.lab1024.sa.admin.module.business.erp.domain.form.query.AccountaQueryForm;
import net.lab1024.sa.admin.module.business.erp.domain.form.update.AccountaUpdateForm;
import net.lab1024.sa.admin.module.business.erp.domain.vo.AccountaVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 生产订单与机器对应表 Service
 *
 * @Author AKITA
 * @Date 2025-04-19 13:14:12
 * @Copyright AKITA
 */

@Service
public class AccountaService {

    @Resource
    private AccountaDao accountaDao;

    /**
     * 分页查询
     */
    public PageResult<AccountaVO> queryPage(AccountaQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<AccountaVO> list = accountaDao.queryPage(page, queryForm);
        return SmartPageUtil.convert2PageResult(page, list);
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(AccountaAddForm addForm) {
        AccountaEntity accountaEntity = SmartBeanUtil.copy(addForm, AccountaEntity.class);
        accountaDao.insert(accountaEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     */
    public ResponseDTO<String> update(AccountaUpdateForm updateForm) {
        AccountaEntity accountaEntity = SmartBeanUtil.copy(updateForm, AccountaEntity.class);
        accountaDao.updateById(accountaEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     */
    public ResponseDTO<String> batchDelete(List<Long> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        accountaDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Long docEntry) {


        accountaDao.deleteById(docEntry);
        return ResponseDTO.ok();
    }
}
